package com.dgut.service.background.controller;

import com.alibaba.fastjson.JSON;
import com.dgut.service.background.config.resultConfig.JsonResult;
import com.dgut.service.background.config.resultConfig.ResultTool;
import com.dgut.service.background.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 健康统计
 */
@RestController
@RequestMapping("health")
public class HealthController {
    @Autowired
    private HealthService healthService;

    //按健康状况获取健康统计
    @GetMapping("healthData")
    public String getHealthData(){
        String[] health = {"健康","乏力","咳嗽","发烧","疑似新冠状病毒感染","确诊新冠状病毒感染"};
        int[] healthData = new int[6];
        int i = 0;
        //获取每一种健康状况的人数
        for (String h:health) {
            healthData[i] = healthService.getHealthData(h);
            i++;
        }
        JsonResult result = ResultTool.success(healthData);
        return JSON.toJSONString(result);
    }

    //按体温获取体温统计
    @GetMapping("tempData")
    public String getTempData(){
        int[] tempData = new int[3];
        //获取每一个温度段的人数
        tempData[0] = healthService.findLessThan(36);
        tempData[1] = healthService.findBetween(36, 37.3);
        tempData[2] = healthService.findGreaterThan(37.3);
        JsonResult result = ResultTool.success(tempData);
        return JSON.toJSONString(result);
    }
}
